const { DataTypes } = require('sequelize');

module.exports = (sequelize) => {
  const PrintReservation = sequelize.define('PrintReservation', {
    id: {
      type: DataTypes.BIGINT.UNSIGNED,
      primaryKey: true,
      autoIncrement: true
    },
    user_id: {
      type: DataTypes.BIGINT.UNSIGNED,
      allowNull: false,
      references: {
        model: 'users',
        key: 'id'
      }
    },
    file_id: {
      type: DataTypes.BIGINT.UNSIGNED,
      allowNull: false,
      references: {
        model: 'files',
        key: 'id'
      }
    },
    config_id: {
      type: DataTypes.BIGINT.UNSIGNED,
      allowNull: false,
      references: {
        model: 'print_configs',
        key: 'id'
      }
    },
    copies: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 1,
      comment: '打印份数'
    },
    pages: {
      type: DataTypes.STRING(255),
      allowNull: true,
      comment: '打印页码范围，如"1-5,8,10-15"'
    },
    total_pages: {
      type: DataTypes.INTEGER,
      allowNull: false,
      comment: '总页数'
    },
    price: {
      type: DataTypes.DECIMAL(10, 2),
      allowNull: false,
      comment: '所需积分'
    },
    status: {
      type: DataTypes.TINYINT,
      allowNull: false,
      defaultValue: 0,
      comment: '状态：0-待确认，1-待打印，2-已完成，3-已取消'
    },
    remark: {
      type: DataTypes.STRING(255),
      allowNull: true,
      comment: '备注'
    },
    pickup_code: {
      type: DataTypes.STRING(10),
      allowNull: true,
      comment: '取件码'
    },
    created_at: {
      type: DataTypes.DATE,
      allowNull: false,
      defaultValue: DataTypes.NOW
    },
    updated_at: {
      type: DataTypes.DATE,
      allowNull: false,
      defaultValue: DataTypes.NOW
    },
    completed_at: {
      type: DataTypes.DATE,
      allowNull: true,
      comment: '完成时间'
    }
  }, {
    tableName: 'print_reservations',
    timestamps: true,
    createdAt: 'created_at',
    updatedAt: 'updated_at'
  });

  return PrintReservation;
};